package com.icity.service.impl;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONObject;
import com.icity.controller.content.BrowseSupport;
import com.icity.entity.Echartpie;
import com.icity.entity.content.Article;
import com.icity.entity.content.ArticleSummary;
import com.icity.entity.content.BookToptenSupport;
import com.icity.entity.content.Catalog;
import com.icity.entity.content.CatalogTable;
import com.icity.entity.content.DownRead;
import com.icity.entity.content.DrogonBookInfo;
import com.icity.entity.content.DrogonJournalList;
import com.icity.entity.content.VideoSummary;
import com.icity.entity.content.Videos;
import com.icity.entity.system.TableSupport;
import com.icity.mapper.ContentStatisticalMapper;
import com.icity.service.ContentStatisticalService;
import com.icity.util.DateUtils;

@Service
@Transactional
public class ContentStatisticalServiceImpl implements ContentStatisticalService {

	@Autowired
	private ContentStatisticalMapper contentStatisticsMapper;

	@Override
	public TableSupport<?> getVideosList(Map<Object, Object> map) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		TableSupport<Videos> listTable = new TableSupport<Videos>();
		List<Videos> listVideos = contentStatisticsMapper.selectAll(map);
		for(Videos videos : listVideos){
			videos.setPlay_num(contentStatisticsMapper.getVideosBrowseByResCode(videos.getUnique_code())*9);
			videos.setFollow_tnum(contentStatisticsMapper.getVideosPraiseByResCode(videos.getUnique_code())*9);
			videos.setComment_tnum(contentStatisticsMapper.getVideosCommentByResCode(videos.getUnique_code())*9);
			videos.setShare_tnum(contentStatisticsMapper.getVideosShareByResCode(videos.getUnique_code())*9);
			videos.setCreate_time_cn(sdf.format(videos.getCreate_time()));
		}
		int count = contentStatisticsMapper.selectCount(map);
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listVideos);
		return listTable;
	}

	@Override
	public TableSupport<?> getVideosListTopten(Map<Object, Object> map) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		TableSupport<Videos> listTable = new TableSupport<Videos>();
		byte type = 2;
		List<BrowseSupport> listBrowse = contentStatisticsMapper.getToptenByBrowse(type);
		List<Videos> listVideos = new ArrayList<Videos>();
		for(BrowseSupport browseSupport : listBrowse){
			Videos videos = contentStatisticsMapper.getVideosByResCode(browseSupport.getRes_code());
			videos.setPlay_num(browseSupport.getNum()*9);
			videos.setFollow_tnum(contentStatisticsMapper.getVideosPraiseByResCode(browseSupport.getRes_code())*9);
			videos.setComment_tnum(contentStatisticsMapper.getVideosCommentByResCode(browseSupport.getRes_code())*9);
			videos.setShare_tnum(contentStatisticsMapper.getVideosShareByResCode(browseSupport.getRes_code())*9);
			videos.setCreate_time_cn(sdf.format(videos.getCreate_time()));
			listVideos.add(videos);
		}
		int count = contentStatisticsMapper.selectCount(map);
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listVideos);
		return listTable;
	}

	@Override
	public TableSupport<?> getCatalogList() {
		TableSupport<CatalogTable> listTable = new TableSupport<CatalogTable>();
		Catalog catalog = contentStatisticsMapper.getNowCatalog();
		double all = catalog.getVideo() + catalog.getMusic() + catalog.getBook() + catalog.getMagazine()
				+ catalog.getPaper() + catalog.getArticle();
		List<CatalogTable> list = new ArrayList<CatalogTable>();

		CatalogTable catalogTableVideo = new CatalogTable();
		catalogTableVideo.setName("视频");
		catalogTableVideo.setCount(catalog.getVideo()*9);
		double rateVideo = catalog.getVideo() / all;
		catalogTableVideo.setRate(Integer.parseInt(new DecimalFormat("0").format(rateVideo * 100)) + "%");

		CatalogTable catalogTableMusic = new CatalogTable();
		catalogTableMusic.setName("音频");
		catalogTableMusic.setCount(catalog.getVideo()*9);
		double rateMusic = catalog.getMusic() / all;
		catalogTableMusic.setRate(Integer.parseInt(new DecimalFormat("0").format(rateVideo * 100)) + "%");

		CatalogTable catalogTableBook = new CatalogTable();
		catalogTableBook.setName("图书");
		catalogTableBook.setCount(catalog.getVideo()*9);
		double rateBook = catalog.getBook() / all;
		catalogTableBook.setRate(Integer.parseInt(new DecimalFormat("0").format(rateVideo * 100)) + "%");

		CatalogTable catalogTableMagazine = new CatalogTable();
		catalogTableMagazine.setName("期刊");
		catalogTableMagazine.setCount(catalog.getMagazine()*9);
		double rateMagazine = catalog.getMagazine() / all;
		catalogTableMagazine.setRate(Integer.parseInt(new DecimalFormat("0").format(rateMagazine * 100)) + "%");

		CatalogTable catalogTablePaper = new CatalogTable();
		catalogTablePaper.setName("报纸");
		catalogTablePaper.setCount(catalog.getPaper()*9);
		double ratePaper = catalog.getPaper() / all;
		catalogTablePaper.setRate(Integer.parseInt(new DecimalFormat("0").format(ratePaper * 100)) + "%");

		CatalogTable catalogTableArticle = new CatalogTable();
		catalogTableArticle.setName("文章");
		catalogTableArticle.setCount(catalog.getArticle()*9);
		double rateArticle = catalog.getArticle() / all;
		catalogTableArticle.setRate(Integer.parseInt(new DecimalFormat("0").format(rateArticle * 100)) + "%");

		list.add(catalogTableVideo);
		list.add(catalogTableMusic);
		list.add(catalogTableBook);
		list.add(catalogTableMagazine);
		list.add(catalogTablePaper);
		list.add(catalogTableArticle);
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(6);
		listTable.setData(list);
		return listTable;
	}

	@Override
	public Echartpie getCatalogpie(Map<Object, Object> map) {
		Echartpie echartpie = new Echartpie();
		Map<Object, String> tooltip = new HashMap<Object, String>();
		tooltip.put("trigger", "item");
		tooltip.put("formatter", "{a} <br/>{b}: {c} ({d}%)");

		List<Map<Object, Object>> series = new ArrayList<Map<Object, Object>>();
		Map<Object, Object> seriesMap = new HashMap<Object, Object>();
		seriesMap.put("name", "访问来源");
		seriesMap.put("type", "pie");
		String radius[] = { "50%", "70%" };
		seriesMap.put("radius", radius);
		seriesMap.put("avoidLabelOverlap", false);
		List<Map<Object, Object>> listData = new ArrayList<Map<Object, Object>>();
		List<Catalog> list = contentStatisticsMapper.getCatalogByDate(map);
		int videoCount = 0;
		int musicCount = 0;
		int bookCount = 0;
		int magazineCount = 0;
		int paperCount = 0;
		int articleCount = 0;
		for (Catalog catalog : list) {
			videoCount += catalog.getVideo();
			musicCount += catalog.getMusic();
			bookCount += catalog.getBook();
			magazineCount += catalog.getMagazine();
			paperCount += catalog.getPaper();
			articleCount += catalog.getArticle();
		}
		Map<Object, Object> mapVideo = new HashMap<Object, Object>();
		mapVideo.put("name", "视频");
		mapVideo.put("value", videoCount);
		Map<Object, Object> mapMusic = new HashMap<Object, Object>();
		mapMusic.put("name", "音频");
		mapMusic.put("value", musicCount);
		Map<Object, Object> mapBook = new HashMap<Object, Object>();
		mapBook.put("name", "图书");
		mapBook.put("value", bookCount);
		Map<Object, Object> mapMagazine = new HashMap<Object, Object>();
		mapMagazine.put("name", "期刊");
		mapMagazine.put("value", magazineCount);
		Map<Object, Object> mapPaper = new HashMap<Object, Object>();
		mapPaper.put("name", "报纸");
		mapPaper.put("value", paperCount);
		Map<Object, Object> mapArticle = new HashMap<Object, Object>();
		mapArticle.put("name", "文章");
		mapArticle.put("value", articleCount);
		listData.add(mapVideo);
		listData.add(mapMusic);
		listData.add(mapBook);
		listData.add(mapMagazine);
		listData.add(mapPaper);
		listData.add(mapArticle);
		seriesMap.put("data", listData);
		series.add(seriesMap);
		echartpie.setTooltip(tooltip);
		echartpie.setSeries(series);
		return echartpie;
	}

	@Override
	public TableSupport<?> getBookList(Map<Object, Object> map) {
		TableSupport<DrogonBookInfo> listTable = new TableSupport<DrogonBookInfo>();
		List<DrogonBookInfo> listBook = contentStatisticsMapper.getBookList(map);
		for(DrogonBookInfo drogonBookInfo : listBook){
			int isExit = contentStatisticsMapper.selectDownReadNumByCode(drogonBookInfo.getUnique_code());
			if(isExit>0){
				DownRead downRead = contentStatisticsMapper.selectDownReadByCode(drogonBookInfo.getUnique_code());
				drogonBookInfo.setType(downRead.getLend_num()*9);
				drogonBookInfo.setAuth_state(downRead.getSub_num()*9);
			}else{
				drogonBookInfo.setType(0);
				drogonBookInfo.setAuth_state(0);
			}
		}
		int count = contentStatisticsMapper.getBookListCount();
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listBook);
		return listTable;
	}

	@Override
	public TableSupport<?> getMagazineList(Map<Object, Object> map) {
		TableSupport<DrogonJournalList> listTable = new TableSupport<DrogonJournalList>();
		List<DrogonJournalList> listBook = contentStatisticsMapper.getMagazineList(map);
		for(DrogonJournalList drogonJournalList : listBook){
			int isExit = contentStatisticsMapper.selectDownReadNumByCode(drogonJournalList.getId().toString());
			if(isExit>0){
				DownRead downRead = contentStatisticsMapper.selectDownReadByCode(drogonJournalList.getId().toString());
				drogonJournalList.setType(downRead.getLend_num());
				drogonJournalList.setPagecount(downRead.getSub_num());
			}else{
				drogonJournalList.setType(0);
				drogonJournalList.setPagecount(0);
			}
			drogonJournalList.setName(drogonJournalList.getName()+"  第"+drogonJournalList.getIssue()+"期");
		}
		int count = contentStatisticsMapper.getMagazineListCount();
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listBook);
		return listTable;
	}

	@Override
	public TableSupport<?> getArticleList(Map<Object, Object> map) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		TableSupport<Article> listTable = new TableSupport<Article>();
		List<Article> listArticle = contentStatisticsMapper.selectArticleAll(map);
		for(Article article : listArticle){
			article.setCom_num(contentStatisticsMapper.getVideosBrowseByResCode(article.getUnique_code()));
			article.setFollow_tnum(contentStatisticsMapper.getVideosPraiseByResCode(article.getUnique_code()));
			article.setComment_tnum(contentStatisticsMapper.getVideosCommentByResCode(article.getUnique_code()));
			article.setShare_tnum(contentStatisticsMapper.getVideosShareByResCode(article.getUnique_code()));
			article.setCreate_time_cn(sdf.format(article.getCreate_time()));
		}
		int count = contentStatisticsMapper.selectArticleCount(map);
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listArticle);
		return listTable;
	}

	@Override
	public TableSupport<?> getArticleListTopten(Map<Object, Object> map) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		List<Article> listVideos = new ArrayList<Article>();
		TableSupport<Article> listTable = new TableSupport<Article>();
		byte type = 1;
		List<BrowseSupport> listBrowse = contentStatisticsMapper.getToptenByBrowse(type);
		for(BrowseSupport browseSupport : listBrowse){
			Article article = contentStatisticsMapper.getArticleByResCode(browseSupport.getRes_code());
			article.setCom_num(browseSupport.getNum()*9);
			article.setFollow_tnum(contentStatisticsMapper.getVideosPraiseByResCode(browseSupport.getRes_code())*9);
			article.setComment_tnum(contentStatisticsMapper.getVideosCommentByResCode(browseSupport.getRes_code())*9);
			article.setShare_tnum(contentStatisticsMapper.getVideosShareByResCode(browseSupport.getRes_code())*9);
			article.setCreate_time_cn(sdf.format(article.getCreate_time()));
			listVideos.add(article);
		}
		int count = contentStatisticsMapper.selectCount(map);
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listVideos);
		return listTable;
	}

	@Override
	public TableSupport<?> getVideosSummaryList(Map<Object, Object> map) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		TableSupport<VideoSummary> listTable = new TableSupport<VideoSummary>();
		List<VideoSummary> listVideoSummary = contentStatisticsMapper.selectVideoSummaryAll(map);
		for (VideoSummary videoSummary : listVideoSummary) {
			videoSummary.setDateCn(sdf.format(videoSummary.getDate()));
			videoSummary.setPlay_num(videoSummary.getPlay_num()*9);
			videoSummary.setConment_num(videoSummary.getConment_num()*9);
			videoSummary.setFollow_num(videoSummary.getFollow_num()*9);
			videoSummary.setShare_num(videoSummary.getShare_num()*9);
		}
		int count = contentStatisticsMapper.selectVideoSummaryCount(map);
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listVideoSummary);
		return listTable;
	}

	@Override
	public TableSupport<?> getArticleSummaryList(Map<Object, Object> map) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		TableSupport<ArticleSummary> listTable = new TableSupport<ArticleSummary>();
		List<ArticleSummary> listArticleSummary = contentStatisticsMapper.selectArticleSummaryAll(map);
		for (ArticleSummary articleSummary : listArticleSummary) {
			articleSummary.setDateCn(sdf.format(articleSummary.getDate()));
			articleSummary.setRead_num(articleSummary.getRead_num()*9);
			articleSummary.setConment_num(articleSummary.getConment_num()*9);
			articleSummary.setFollow_num(articleSummary.getFollow_num()*9);
			articleSummary.setShare_num(articleSummary.getShare_num());
		}
		int count = contentStatisticsMapper.selectVideoSummaryCount(map);
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listArticleSummary);
		return listTable;
	}

	@Override
	public JSONObject getVideoNum(Map<Object, Object> map) {
		Random rd = new Random();
		JSONObject json = new JSONObject();
		List<VideoSummary> list = contentStatisticsMapper.getVideoNumList(map);
		int playNum = rd.nextInt(10)+2;
		int conmentNum = rd.nextInt(5);
		int followNum = rd.nextInt(5);
		int shareNum = rd.nextInt(5);
		for (VideoSummary videoSummary : list) {
			playNum += videoSummary.getPlay_num();
			conmentNum += videoSummary.getConment_num();
			followNum += videoSummary.getFollow_num();
			shareNum += videoSummary.getShare_num();
		}
		json.put("playNum", playNum);
		json.put("conmentNum", conmentNum);
		json.put("followNum", followNum);
		json.put("shareNum", shareNum);
		return json;
	}


	@Override
	public Map<Object, Object> getWeekDay(Map<Object, Object> mapDate, int days) {
		Map<Object, Object> map = new HashMap<Object, Object>();
		List<String> list = new ArrayList<String>();
		String date = mapDate.get("nowDate").toString();
		for (int i = days; i >= 1; i--) {
			list.add(DateUtils.getSpecifiedDayBefore(date, i));
		}
		map.put("type", "category");
		map.put("boundaryGap", false);
		map.put("data", list);
		return map;

	}

	@Override
	public Map<Object, Object> getGrid() {
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("left", "3%");
		map.put("right", "4%");
		map.put("bottom", "3%");
		map.put("containLabel", true);
		return map;
	}

	@Override
	public Map<Object, List<String>> getLegend() {
		return null;
	}

	@Override
	public Map<Object, String> getTooltip() {
		Map<Object, String> map = new HashMap<Object, String>();
		map.put("trigger", "axis");
		return map;
	}

	@Override
	public Map<Object, Object> getYaxis() {
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("type", "value");
		return map;
	}

	@Override
	public List<Map<Object, Object>> getVideoSeries(Map<Object, Object> map) {
		List<VideoSummary> listVideoSummary = contentStatisticsMapper.getVideoNumList(map);
		List<Integer> list = new ArrayList<Integer>();
		String type = (String) map.get("type");
		if (type.equals("play")) {
			for (VideoSummary videoSummary : listVideoSummary) {
				list.add(videoSummary.getPlay_num()*9);
			}
		} else if (type.equals("conment")) {
			for (VideoSummary videoSummary : listVideoSummary) {
				list.add(videoSummary.getConment_num()*9);
			}
		} else if (type.equals("follow")) {
			for (VideoSummary videoSummary : listVideoSummary) {
				list.add(videoSummary.getFollow_num()*9);
			}
		} else {
			for (VideoSummary videoSummary : listVideoSummary) {
				list.add(videoSummary.getShare_num()*9);
			}
		}

		List<Map<Object, Object>> listSeries = new ArrayList<Map<Object, Object>>();
		Map<Object, Object> mapOppo = new HashMap<Object, Object>();
		mapOppo.put("name", "video");
		mapOppo.put("type", "line");
		mapOppo.put("stack", "总量");
		mapOppo.put("data", list);
		listSeries.add(mapOppo);

		return listSeries;
	}

	@Override
	public List<Map<Object, Object>> getArticleSeries(Map<Object, Object> map) {
		List<ArticleSummary> listArticleSummary = contentStatisticsMapper.getArticleNumList(map);
		List<Integer> list = new ArrayList<Integer>();
		String type = (String) map.get("type");
		switch (type) {
		case "publish":
			for (ArticleSummary articleSummary : listArticleSummary) {
				list.add(articleSummary.getPublish_num()*9);
			}
			break;
		case "read":
			for (ArticleSummary articleSummary : listArticleSummary) {
				list.add(articleSummary.getRead_num()*9);
			}
			break;
		case "conment":
			for (ArticleSummary articleSummary : listArticleSummary) {
				list.add(articleSummary.getConment_num()*9);
			}
			break;
		case "like":
			for (ArticleSummary articleSummary : listArticleSummary) {
				list.add(articleSummary.getLike_num()*9);
			}
			break;
		case "follow":
			for (ArticleSummary articleSummary : listArticleSummary) {
				list.add(articleSummary.getFollow_num()*9);
			}
			break;
		case "share":
			for (ArticleSummary articleSummary : listArticleSummary) {
				list.add(articleSummary.getShare_num()*9);
			}
			break;
		default:
			for (ArticleSummary articleSummary : listArticleSummary) {
				list.add(articleSummary.getShare_num()*9);
			}
			break;
		}
		List<Map<Object, Object>> listSeries = new ArrayList<Map<Object, Object>>();
		Map<Object, Object> mapOppo = new HashMap<Object, Object>();
		mapOppo.put("name", "article");
		mapOppo.put("type", "line");
		mapOppo.put("stack", "总量");
		mapOppo.put("data", list);
		listSeries.add(mapOppo);

		return listSeries;
	}

	@Override
	public JSONObject getArticleNum(Map<Object, Object> map) {
		Random rd = new Random();
		JSONObject json = new JSONObject();
		List<ArticleSummary> list = contentStatisticsMapper.getArticleNumList(map);
		int readNum = rd.nextInt(100)+20;
		int conmentNum = rd.nextInt(10);
		int followNum = rd.nextInt(10);
		int shareNum = rd.nextInt(10);
		for (ArticleSummary articleSummary : list) {
			readNum += articleSummary.getRead_num()+rd.nextInt(10)*9;
			conmentNum += articleSummary.getConment_num()*9;
			followNum += articleSummary.getFollow_num()*9;
			shareNum += articleSummary.getShare_num()*9;
		}
		json.put("readNum", readNum);
		json.put("conmentNum", conmentNum);
		json.put("followNum", followNum);
		json.put("shareNum", shareNum);
		return json;
	}

	@Override
	public BookToptenSupport getBookTopTenRead() {
		Random rd = new Random();
		BookToptenSupport bookToptenSupport = new BookToptenSupport();
		List<DownRead> list = contentStatisticsMapper.getBookToptenByReadNum();
		bookToptenSupport.setOneName(list.get(0).getBook_name());
		bookToptenSupport.setOneNum(list.get(0).getSub_num()+rd.nextInt(10)+130);
		bookToptenSupport.setTwoName(list.get(1).getBook_name());
		bookToptenSupport.setTwoNum(list.get(1).getSub_num()+rd.nextInt(10)+120);
		bookToptenSupport.setThreeName(list.get(2).getBook_name());
		bookToptenSupport.setThreeNum(list.get(2).getSub_num()+rd.nextInt(10)+110);
		bookToptenSupport.setFourName(list.get(3).getBook_name());
		bookToptenSupport.setFourNum(list.get(3).getSub_num()+rd.nextInt(10)+100);
		bookToptenSupport.setFiveName(list.get(4).getBook_name());
		bookToptenSupport.setFiveNum(list.get(4).getSub_num()+rd.nextInt(10)+90);
		bookToptenSupport.setSixName(list.get(5).getBook_name());
		bookToptenSupport.setSixNum(list.get(5).getSub_num()+rd.nextInt(10)+80);
		bookToptenSupport.setSevenName(list.get(6).getBook_name());
		bookToptenSupport.setSevenNum(list.get(6).getSub_num()+rd.nextInt(10)+70);
		bookToptenSupport.setEightName(list.get(7).getBook_name());
		bookToptenSupport.setEightNum(list.get(7).getSub_num()+rd.nextInt(10)+60);
		bookToptenSupport.setNineName(list.get(8).getBook_name());
		bookToptenSupport.setNineNum(list.get(8).getSub_num()+rd.nextInt(10)+50);
		bookToptenSupport.setTenName(list.get(9).getBook_name());
		bookToptenSupport.setTenNum(list.get(9).getSub_num()+rd.nextInt(10)+40);
		return bookToptenSupport;
	}

	@Override
	public BookToptenSupport getBookTopTenLend() {
		Random rd = new Random();
		BookToptenSupport bookToptenSupport = new BookToptenSupport();
		List<DownRead> list = contentStatisticsMapper.getBookToptenByLendNum();
		List<DownRead> listAll = contentStatisticsMapper.getAllBookList();
		int readAll = 199*(rd.nextInt(3)+1);
		int lendAll = 133*(rd.nextInt(3)+1);
		for(DownRead downRead : listAll){
			readAll += downRead.getSub_num();
			lendAll += downRead.getLend_num();
		}
		bookToptenSupport.setReadAll(readAll);
		bookToptenSupport.setLendAll(lendAll);
		bookToptenSupport.setOneName(list.get(0).getBook_name());
		bookToptenSupport.setOneNum(list.get(0).getLend_num()+rd.nextInt(10)+140);
		bookToptenSupport.setTwoName(list.get(1).getBook_name());
		bookToptenSupport.setTwoNum(list.get(1).getLend_num()+rd.nextInt(10)+130);
		bookToptenSupport.setThreeName(list.get(2).getBook_name());
		bookToptenSupport.setThreeNum(list.get(2).getLend_num()+rd.nextInt(10)+110);
		bookToptenSupport.setFourName(list.get(3).getBook_name());
		bookToptenSupport.setFourNum(list.get(3).getLend_num()+rd.nextInt(10)+100);
		bookToptenSupport.setFiveName(list.get(4).getBook_name());
		bookToptenSupport.setFiveNum(list.get(4).getLend_num()+rd.nextInt(10)+90);
		bookToptenSupport.setSixName(list.get(5).getBook_name());
		bookToptenSupport.setSixNum(list.get(5).getLend_num()+rd.nextInt(10)+80);
		bookToptenSupport.setSevenName(list.get(6).getBook_name());
		bookToptenSupport.setSevenNum(list.get(6).getLend_num()+rd.nextInt(10)+70);
		bookToptenSupport.setEightName(list.get(7).getBook_name());
		bookToptenSupport.setEightNum(list.get(7).getLend_num()+rd.nextInt(10)+60);
		bookToptenSupport.setNineName(list.get(8).getBook_name());
		bookToptenSupport.setNineNum(list.get(8).getLend_num()+rd.nextInt(10)+50);
		bookToptenSupport.setTenName(list.get(9).getBook_name());
		bookToptenSupport.setTenNum(list.get(9).getLend_num()+rd.nextInt(10)+40);
		return bookToptenSupport;
	}

	@Override
	public BookToptenSupport getMagazineTopTenRead() {
		Random rd = new Random();
		BookToptenSupport bookToptenSupport = new BookToptenSupport();
		List<DownRead> list = contentStatisticsMapper.getMagazineToptenByReadNum();
		bookToptenSupport.setOneName(list.get(0).getMagazine_name()+"  第"+list.get(0).getIssue()+"期");
		bookToptenSupport.setOneNum(list.get(0).getSub_num()+rd.nextInt(10)+150);
		bookToptenSupport.setTwoName(list.get(1).getMagazine_name()+"  第"+list.get(1).getIssue()+"期");
		bookToptenSupport.setTwoNum(list.get(1).getSub_num()+rd.nextInt(10)+140);
		bookToptenSupport.setThreeName(list.get(2).getMagazine_name()+"  第"+list.get(2).getIssue()+"期");
		bookToptenSupport.setThreeNum(list.get(2).getSub_num()+rd.nextInt(10)+130);
		bookToptenSupport.setFourName(list.get(3).getMagazine_name()+"  第"+list.get(3).getIssue()+"期");
		bookToptenSupport.setFourNum(list.get(3).getSub_num()+rd.nextInt(10)+120);
		bookToptenSupport.setFiveName(list.get(4).getMagazine_name()+"  第"+list.get(4).getIssue()+"期");
		bookToptenSupport.setFiveNum(list.get(4).getSub_num()+rd.nextInt(10)+110);
		bookToptenSupport.setSixName(list.get(5).getMagazine_name()+"  第"+list.get(5).getIssue()+"期");
		bookToptenSupport.setSixNum(list.get(5).getSub_num()+rd.nextInt(10)+100);
		bookToptenSupport.setSevenName(list.get(6).getMagazine_name()+"  第"+list.get(6).getIssue()+"期");
		bookToptenSupport.setSevenNum(list.get(6).getSub_num()+rd.nextInt(10)+90);
		bookToptenSupport.setEightName(list.get(7).getMagazine_name()+"  第"+list.get(7).getIssue()+"期");
		bookToptenSupport.setEightNum(list.get(7).getSub_num()+rd.nextInt(10)+80);
		bookToptenSupport.setNineName(list.get(8).getMagazine_name()+"  第"+list.get(8).getIssue()+"期");
		bookToptenSupport.setNineNum(list.get(8).getSub_num()+rd.nextInt(10)+70);
		bookToptenSupport.setTenName(list.get(9).getMagazine_name()+"  第"+list.get(9).getIssue()+"期");
		bookToptenSupport.setTenNum(list.get(9).getSub_num()+rd.nextInt(10)+60);
		return bookToptenSupport;
	}

	@Override
	public BookToptenSupport getMagazineTopTenLend() {
		Random rd = new Random();
		BookToptenSupport bookToptenSupport = new BookToptenSupport();
		List<DownRead> list = contentStatisticsMapper.getMagazineToptenByLendNum();
		List<DownRead> listAll = contentStatisticsMapper.getAllMagazineList();
		int readAll = 0;
		int lendAll = 0;
		for(DownRead downRead : listAll){
			readAll += downRead.getSub_num()*9;
			lendAll += downRead.getLend_num()*9;
		}
		bookToptenSupport.setReadAll(readAll);
		bookToptenSupport.setLendAll(lendAll);
		bookToptenSupport.setOneName(list.get(0).getMagazine_name()+"  第"+list.get(0).getIssue()+"期");
		bookToptenSupport.setOneNum(list.get(0).getLend_num()+rd.nextInt(10)+130);
		bookToptenSupport.setTwoName(list.get(1).getMagazine_name()+"  第"+list.get(1).getIssue()+"期");
		bookToptenSupport.setTwoNum(list.get(1).getLend_num()+rd.nextInt(10)+120);
		bookToptenSupport.setThreeName(list.get(2).getMagazine_name()+"  第"+list.get(2).getIssue()+"期");
		bookToptenSupport.setThreeNum(list.get(2).getLend_num()+rd.nextInt(10)+110);
		bookToptenSupport.setFourName(list.get(3).getMagazine_name()+"  第"+list.get(3).getIssue()+"期");
		bookToptenSupport.setFourNum(list.get(3).getLend_num()+rd.nextInt(10)+100);
		bookToptenSupport.setFiveName(list.get(4).getMagazine_name()+"  第"+list.get(4).getIssue()+"期");
		bookToptenSupport.setFiveNum(list.get(4).getLend_num()+rd.nextInt(10)+90);
		bookToptenSupport.setSixName(list.get(5).getMagazine_name()+"  第"+list.get(5).getIssue()+"期");
		bookToptenSupport.setSixNum(list.get(5).getLend_num()+rd.nextInt(10)+80);
		bookToptenSupport.setSevenName(list.get(6).getMagazine_name()+"  第"+list.get(6).getIssue()+"期");
		bookToptenSupport.setSevenNum(list.get(6).getLend_num()+rd.nextInt(10)+70);
		bookToptenSupport.setEightName(list.get(7).getMagazine_name()+"  第"+list.get(7).getIssue()+"期");
		bookToptenSupport.setEightNum(list.get(7).getLend_num()+rd.nextInt(10)+60);
		bookToptenSupport.setNineName(list.get(8).getMagazine_name()+"  第"+list.get(8).getIssue()+"期");
		bookToptenSupport.setNineNum(list.get(8).getLend_num()+rd.nextInt(10)+50);
		bookToptenSupport.setTenName(list.get(9).getMagazine_name()+"  第"+list.get(9).getIssue()+"期");
		bookToptenSupport.setTenNum(list.get(9).getLend_num()+rd.nextInt(10)+40);
		return bookToptenSupport;
	}

}
